<?php
if(!defined('IN_WOGU')) {
    exit('Access Denied');
}

class Respones
{
    public $returnRespones = false;
    protected $_headers = array();
    protected $_body = '';
    
    public function __construct() {
        $this->_headers['contentType'] = 'Content-Type: text/html; charset=' . CHARSET;
    }
    
    public function setHeader($header, $name = null) {
        if($name == null) {
            $this->_headers[] = $header;
        } else {
            $this->_headers[$name] = $header;
        }
    }
    
    public function getHeaders() {
        return $this->_headers;
    }
    
    public function setBody($body) {
        $this->_body = $body;
    }
    
    public function getBody() {
        return $this->_body;
    }

    public function sendRespones() {
        //发送头部
        if(!empty($this->_headers)) {
            foreach($this->_headers as $header) {
                header($header);
            }
        }

        if($this->returnRespones) {
            return $this->_body;
        }

        echo $this->_body;
        return true;
    }
}